pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Build'
}
}
stage('Test') {
steps {
echo 'Test'
}
}
stage('Deploy') {
steps {
echo 'Deploy'
}
}
}
}NightClazz Lille - 4 Décembre 2017
Damien DUPORTAL & Jean-Marc MEESSEN
Training Engineer @ CloudBees
Docker & Apple fanboy.
Human stack focused
Rock climber
Contact:
Twitter: @DamienDuportal
Github: dduportal
eMail: damien.duportal@gmail.com
Customer Success Manager @ CloudBees
Explorer of the great things out there
Loves to share his discoveries
Not too old for great adventures
Contact:
Twitter: @JM_Meessen
Github: jmMeessen
eMail: jean-marc@meessen-web.org
Y a-t-il des développeurs ici ?
Qui pratique l’Intégration Continue ?
Avec quels outils ?
Jenkins "Old School" ? / "New Generation" ?
GitLab ? TeamCity ? TravisCI ? Bamboo ?
Autre ?
Présentation générale
Jenkins Pipelines
Blue Ocean
Donner des pistes d’exploration
Mais c’est mieux avec un atelier (Lab)
Each integration is verified by an automated build (including test)
Integrate code often, at least daily, to make integration a non-event
Continuously build and integrate, with a feedback loop
Logiciel Open Source
Orchestrateur de tâches
Un des tout premiers moteur d’intégration continue
Architecture centrée sur les plugins
Un gigantesque écosystème
Pierre angulaire de l’évolution de Jenkins
Visualisation et manipulation de "Pipelines"
GUI moderne, se concentrant sur les actions principales
Un outil pour définir votre flux de Continuous Delivery/Deployment avec votre code
!= outil de création de job comme "Job DSL"
Survive the Jenkins master restarts
Reduces number of jobs
Easier specification through code
Le Pipeline est décrit dans un fichier texte: le JenkinsFile
DSL spécifique
stocké dans un SCM
versionné
isolation par branche
suit les patterns à la “Git / Github / Gitlab flow”
Pipeline-as-code: We need a Jenkinsfile
Where to start ?
Declarative
Default syntax
Used with Blue Ocean
Scripted
Original syntax (~3 years)
"Great Power == Great Responsibility"
Use it when Declarative starts to be weird
Provides the full round trip with SCM
No Pipeline ? Follow the wizard.
Already have a Pipeline ? Edit, commit, and run it
Get the AWS DNS name of your machine
Open the URL YOUR_INSTANCE_DNS:10000
Welcome to the Lab Home Page
Click the link Workshop Slides
Browse to this current slide
Access the Gitea git server:
Log in as the user butler (password is the same)
Access the source code:
Once authenticated, click on Explore (on top)
Click on butler/demoapp
Direct link: http://localhost:10000/gitserver/butler/demoapp
Access your Jenkins instance:
Log in as the user butler (password is the same)
This is the "Jenkins Classic GUI"
Switch to Blue Ocean:
Or click on the item "Open Blue Ocean", on the left menu
Create a new Pipeline, with the following properties:
Stored in Git
Get the SSH URL from the git server
Configure Jenkins access to the source code:
In Gitea, click the top-right user drop down
Browse to SSH/GPG Keys
Add a new key, by copy and pasting from Jenkins
Click the button Create a Pipeline
Use the Blue Ocean Pipeline Editor and Gitea git server
Create a Pipeline that have 3 stages: Build, Test and Deploy
Each stage has 1 step that prints a message
"Building…" for Build, "Testing…" for Test…
Save, add a commit message and see the build kicking off
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Build'
}
}
stage('Test') {
steps {
echo 'Test'
}
}
stage('Deploy') {
steps {
echo 'Deploy'
}
}
}
}Using the Blue Ocean Pipeline Editor:
Edit the current Pipeline’s 3 stages to run scripts
Scripts are stored in the ./scripts folder (in SCM)
Use the step Shell Script (keyword sh)
Remove the echo steps
Save, add a commit message and see the build kicking off
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './scripts/build.sh'
}
}
stage('Test') {
steps {
sh './scripts/test.sh'
}
}
stage('Deploy') {
steps {
sh './scripts/deploy.sh'
}
}
}
}Using the Blue Ocean Pipeline Editor:
Edit the current Pipeline
Build stage should archive all *.jar files found in ./target
Test stage should publish the junit test reports
Found in ./target. TIP for recusrive: */.xml
Save, add a commit message and see the build kicking off
Build should be UNSTABLE
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './scripts/build.sh'
archiveArtifacts 'target/*.jar'
}
}
stage('Test') {
steps {
sh './scripts/test.sh'
junit 'target/**/*.xml'
}
}
stage('Deploy') {
steps {
sh './scripts/deploy.sh'
}
}
}
}Le build est en état UNSTABLE (jaune)
Priorité: réparer le build
Utiliser Gitea git server
Les tests d’intégration sont dans src/tests/java/hello
Indices:
Integration Tests: == IT
Il suffit de savoir commenter/dé-commenter
Depuis src/test/java/hello/HelloControllerIT.java
Cliquer sur "Edit"
Commenter la ligne 39
Dé-commenter la ligne 40
Commit avec un message (push automatique)
Lancer le build manuellement dans Blue Ocean
Le build doit être vert (Stable)
Nous avons dû lancer le build manuellement
IC: Retours rapides !
Lancer le build dès que le code est poussé
Configurons un "Webhook" :
Depuis Gitea git server → Settings → Webhooks
Ajouter un nouveau webhook:
Type: Gitea
When should this webhook be triggered?: I need everything
Payload URL: http://localhost:10000/jenkins/job/demoapp/build?delay=0
Ajoutez un commentaire dans le Jenkinsfile depuis Gitea git server
Un build va démarrer
Validez dans l’onglet "Changes"
Dans l’éditeur Blue Ocean, voir la version textuelle:
Combinaison CTRL + S (On Mac: CMD +S)
Bi-directionnel: essayez de charger une solution de pipeline
Le Pipeline Syntax Snippet Generator comme acolyte:
Génération dynamique en fonction de vos plugins
Depuis l’interface "ancienne" de Jenkins
Menu de gauche de votre job "Pipeline" (ou MultiBranch)
But: réutiliser les binaires générés dans Build
Action: "mise sur étagère": Stash / Unstash
Modifier le Pipeline pour :
"Stasher" le dossier target, à la fin de la phase Build
"Unstasher" au début de la phase Test
Attention, une limite de l’éditeur Blue Ocean va être atteinte
L’éditeur Blue Ocean ne supporte pas encore le ré-ordonnancement de "stages"
Mode textuel et/ou Snippet Generator à utiliser
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './scripts/build.sh'
archiveArtifacts 'target/*.jar'
stash(name: 'build-result', includes: 'target/**/*')
}
}
stage('Test') {
steps {
unstash 'build-result'
sh './scripts/test.sh'
junit 'target/**/*.xml'
}
}
stage('Deploy') {
steps {
sh './scripts/deploy.sh'
}
}
}
}Section post :
Contient des "steps" à exécuter à la fin du Pipeline ou après une "stage"
Divisé en "condition d’états":
always, success, failure, changed
Chaque condition contient ses propres "steps"
Pas encore intégré dans l’éditeur Blue Ocean
Si le "stage" Build échoue, alors la tâche "archiveArtifacts" ne devrait pas être exécutée
Même chose pour stash
Le rapports de tests unitaires doivent être publiés dans tous les cas
Format Junit
Stockés dans ./target/surefire-reports/*/.xml
Utiliser la documentation:
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './scripts/build.sh'
}
post {
always {
junit 'target/surefire-reports/**/*.xml'
}
success {
archiveArtifacts 'target/*.jar'
stash(name: 'build-result', includes: 'target/**/*')
}
}
}
stage('Test') {
steps {
unstash 'build-result'
sh './scripts/test.sh'
junit 'target/**/*.xml'
}
}
stage('Deploy') {
steps {
sh './scripts/deploy.sh'
}
}
}
}